<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	 Object sessionTime  = request.getSession().getAttribute("orders_time_start");
	  
	
%>
<!DOCTYPE html >
<html>
<head>
</head>
<c:if test="${code==1}">
	 <script type="text/javascript">
	 	
	
		var interval;  //定时器
		$(function() {
	    	    $('#outside_div').mousemove(function(){
				 		$("#my_audio")[0].pause();  //暂停
				 		$("#my_audio")[0].load();  //重载
    			 }); 
		    
			     //定时器标记
			     var  ordersTimeStart= "<%=sessionTime%>"+""; 
			     if(ordersTimeStart!=null&&ordersTimeStart=="true"){   //如果标记为开启
			    	 run(); //加载页面时启动定时器  
			     }else{    //如果标记为关闭
			    		//定时器按钮显示关闭效果
			    		 clearTimeout(interval);
						$("#timeOutControll_Wait").attr("class", "delete");
						$("#timeOutControll_Wait").find('span').text('已关闭定时器');
			     }
					
				 function run() {
					clearTimeout(interval);
					interval = setInterval(chat, "15000");
				 }
				 
			     if(audioPlay){    //判断全局变量标记，是否播放 ,变量放在<script src="jsutil/static.js"" type="text/javascript">
						 $("#my_audio")[0].play();
				 }
		 });
		
		//定时器执行内容
		function chat() {
			var len =$("#searchOrders_div_interval").length;
			if(len>0){
				$.ajax({
					type:'post',
					url:'<%=basePath%>ifNewOrderIncome',
					success : function(data) {
						if (data == 'true') { //有新订单，播放音乐
							audioPlay=true;  
							$("#searchOrders_search").submit();  //刷新表单
						} else if (data == 'false') { //无新订单
							audioPlay=false;
						}
					}
				});
			}else{
				clearTimeout(interval);  //取消定时器
			}
		}

		//定时器开关
		function timeOutControll(obj) {
			if ($(obj).attr("class") == "add") {//关闭定时器  
				clearTimeout(interval);
				$(obj).attr("class", "delete");
				$(obj).find('span').text('已关闭定时器');
			} else if ($(obj).attr("class") == "delete") { //开启定时器  
				interval = setInterval(chat, "30000");
				$(obj).attr("class", "add");
				$(obj).find('span').text('已开启定时器');
			}
		}
		function dealOrder(obj)
		{
			
			if(obj!=null)
			{
				 var dealStatus=0;
				if(obj.innerHTML=='已处理')
					{
					dealStatus=0;
					}
				if(obj.innerHTML=='未处理')
					{
					dealStatus=1;
					}
				$.ajax({
					type:'post',
					url:'<%=basePath%>dealOrder',
				    data: {id:obj.id,dealStatus:dealStatus},
					success : function(data) {
						if (data == 'true') { //处理成功
							if(obj.innerHTML=='已处理')
							{	 $(obj).css("color","red");
								 $(obj).text('未处理');
							}else
							{
							 $(obj).css("color","gray");
							 $(obj).text('已处理');
							}
						} else if (data == 'false') { 
							alert(data);
						}
					}
				});
			}
		}
		
	</script> 
<body >
<div id="searchOrders_div_interval"></div>

	<div id="outside_div">

		 <audio id="my_audio" src="<%=basePath%>music/music.mp3" controls="controls" loop hidden="true">
		</audio> 


		<form id="pagerForm" method="post" action="ordersAction.action?toResult=searchOrders&rightId=${rightId}&baseStatus=NOT_ASSIGNED">
			<input type="hidden" name="pageNum" value="${page.currentPage }" /> 
			<input type="hidden" name="pageSize" value="${page.pageSize }" />
			<input type="hidden" name="senderTelephone" value="${senderTelephone}" />
			<input type="hidden" name="netsiteName" value="${netsiteName}" />
			<input type="hidden" name="endDate" value="${endDate}" />
			<input type="hidden" name="searchDays" value="${searchDays}" />
		</form>

		<form id="searchOrders_search" onsubmit="return navTabSearch(this);" action="ordersAction.action?toResult=searchOrders&rightId=${rightId}&baseStatus=NOT_ASSIGNED" method="post">
			<div class="pageHeader">
				<input type="hidden" name="init" value=0>
				<div class="searchBar">
					<table class="searchContent">
						<tr>
							<td>快递单号: <input type="text" name="expressOrderNo" />
							</td>
							<td>寄件人电话: <input type="text" name="senderTelephone" value="${senderTelephone}"/>
							</td>
							<!-- <td>快递员名称: <input type="text" name="courierName" />
						</td> -->
							<td>网点名称: <input type="text" name="netsiteName" value="${netsiteName}"/>
							</td>
						   	<td>截止日期:<input id="search_endDate"  type="text" class="date" name="endDate" value="${endDate} "
								style="width:100px;"	 readonly="readonly" />
								</td>	
							<td>查询天数:<input onkeyup="value=value.replace(/[^\d.]/g,'')" type="text" min="1" name="searchDays" value="${searchDays}" style="width:50px;" />
							</td>	
							<td>开始日期:<input disabled="disabled" id="search_startDate"  type="text"  name="startDate" value="${startDate} " style="width:100px;"
									readonly="readonly" />
							</td>	
							<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
							<td>
								<div class="buttonActive">
									<div class="buttonContent">
										<button type="submit">检索</button>
									</div>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div class="pageContent">
				<div class="panelBar">
					<ul class="toolBar">
						<c:forEach items="${righSubtList}" var="rightsub">
							<!-- 添加  
						<c:if test="${fn:contains(rightsub.rightValue,'addCourier')}">
							<li><a class="add" href="${rightsub.rightValue}&rightId=${rightId}" target="navTab"><span>${rightsub.rightName}</span> </a>
							</li>
							<li class="line">line</li>
						</c:if>-->
							<!-- 修改  -->
							<c:if test="${fn:contains(rightsub.rightValue,'cancleOrders')}">
								<li><a class="edit" href="${rightsub.rightValue}?supportID={sid_support}&rightId=${rightId}" target="ajaxTodo" title="确认要取消吗？"><span>${rightsub.rightName}</span> </a></li>
								<li class="line">line</li>
							</c:if>
							<!-- 查询详细  -->
							<c:if test="${fn:contains(rightsub.rightValue,'searchDetailOrders')}">
								<li><a class="edit" href="${rightsub.rightValue}?supportID={sid_support}&rightId=${rightId}" target="dialog" width="1200" height="650" mask="true"><span>${rightsub.rightName}</span> </a></li>
								<li class="line">line</li>
							</c:if>
							<!-- 分配网点   -->
							<c:if test="${fn:contains(rightsub.rightValue,'updateOrders')}">
								<li><a class="edit" href="${rightsub.rightValue}&supportID={sid_support}&rightId=${rightId}" target="navTab" width="800" height="500" mask="true"><span>${rightsub.rightName}</span> </a></li>
								<li class="line">line</li>
							</c:if>
							<!-- 发送微信   -->
							<c:if test="${fn:contains(rightsub.rightValue,'sendOrdersWX')}">
								<li><a class="edit" href="${rightsub.rightValue}&supportID={sid_support}&rightId=${rightId}" target="navTab" width="800" height="500" mask="true"><span>${rightsub.rightName}</span> </a></li>
								<li class="line">line</li>
							</c:if>							
							<!-- 更新订单状态   -->
							<c:if test="${fn:contains(rightsub.rightValue,'updateOrderStatus')}">
								<li><a class="edit" href="${rightsub.rightValue}&supportID={sid_support}&rightId=${rightId}" target="navTab" width="800" height="500" mask="true"><span>${rightsub.rightName}</span> </a></li>
								<li class="line">line</li>
							</c:if>								
							<!-- 给客户发送短消息 -->
							<c:if test="${fn:contains(rightsub.rightValue,'sendSms')}">
								<li><a class="add" href="${rightsub.rightValue}&supportID={sid_support}&rightId=${rightId}"  target="navTab" width="800" height="500" mask="true"><span>${rightsub.rightName}</span></a>		</li>
								<li class="line">line</li>
							</c:if>
							<!-- 给快递兔发送短消息 -->	 	
							<c:if test="${fn:contains(rightsub.rightValue,'sendSMSToCourier')}">
								<li><a class="add" href="${rightsub.rightValue}&supportID={sid_support}&rightId=${rightId}"  target="navTab" width="800" height="500" mask="true"><span>${rightsub.rightName}</span></a>		</li>
								<li class="line">line</li>
							</c:if>	 
						</c:forEach>
						<li><a id="timeOutControll_Wait" class="add" href="javascript:void(0)" onclick="timeOutControll(this)"><span>已开启定时器</span> </a></li>
						<li class="line">line</li>
					</ul>
				</div>
				<table class="list" width="100%" layoutH="138">
					<thead>
						<tr>
							<th align="center">序号</th>
							<th align="center">基础订单号</th>
							<th align="center">小订单数</th>
							<th align="center">用户名</th>
						 <!--<th align="center">微信openId</th> -->
							<th align="center">寄件人电话</th>
							<th align="center">寄件人姓名</th>
							<th align="center">订单来源</th>
							<th align="center">订单状态</th>
							 <th align="center">快递员</th>
					<!--<th align="center">快递单号</th> -->
							<th align="center">快递公司</th>
							<th align="center">快递网点</th>
						<!-- 	<th align="center">是否支持打印</th> -->
							<th align="center">寄件地址</th>
							<th align="center">生成时间</th>
							<!-- <th align="center">备注</th> -->
							<th align="center">处理</th>
							<th align="center">支付金额</th>
							<th align="center">优惠金额</th>
						</tr>
					</thead>
					<tbody>
						<s:iterator var="orders" value="page.data" status="st">
							<tr target="sid_support" rel="<s:property value="#orders.id" />">
								<th width="1%" align="center"><s:property value="page.pageSize * (page.currentPage-1) + #st.index + 1" /></th>
								<th width="3%" align="left"><s:property value="#orders.baseOrderNo" /></th>
								<th width="3%" align="left" >
								<s:if test="#orders.ordersCount>1">
										<span style="color: red">${orders.ordersCount}(多)</span>
									</s:if> <s:elseif test="#orders.ordersCount==1">
										<span style="color: purple">${orders.ordersCount}</span>
									</s:elseif>
									</th>
<%-- 								<th width="3%" align="left"><s:property value="#orders.ordersCount" /></th>
 --%>								<th width="3%" align="left"><s:property value="#orders.username" /></th>
							<%--<th width="3%" align="left"><s:property value="#orders.wxOpenId" /></th> --%>
								<th width="3%" align="left"><s:property value="#orders.senderTelephone" /></th>
								<th width="3%" align="left"><s:property value="#orders.senderName" /></th>
								<th width="3%" align="left"><s:property value="#orders.source" /></th>
								<th width="4%" align="left"><s:if test="#orders.orderStatus=='NOT_ASSIGNED'">
										<span style="color: blue">等待接单</span>
									</s:if> <s:elseif test="#orders.orderStatus=='NETSITE_CANCELLED_NOTINAREA'">
										<span style="color: purple">不在范围</span>
									</s:elseif> <s:elseif test="#orders.orderStatus=='NETSITE_CANCELLED_MENDACIOUS'">
										<span style="color: grey">虚假订单</span>
									</s:elseif> <s:elseif test="#orders.orderStatus=='ACCEPTED'">
										<span style="color: RosyBrown">等待取件_未打印</span>
									</s:elseif> <s:elseif test="#orders.orderStatus=='ACCEPTED_PRINTED'">
										<span style="color: brown">等待取件_已打印</span>
									</s:elseif>	<s:elseif test="#orders.orderStatus=='PICKED'">
										<span style="color: DarkOrchid">取件成功_未录入</span>
									</s:elseif> <s:elseif test="#orders.orderStatus=='PICKED_INPUT'">
										<span style="color: green">取件成功_已录入</span>
									</s:elseif> <s:elseif test="#orders.orderStatus=='CANCELLED'">
										<span style="color: red">订单取消</span>
									</s:elseif></th>
								 <th width="3%" align="left"><s:property value="#orders.courierName" /></th>
								<%--<th width="4%" align="left"><s:property value="#orders.expressOrderNo" /></th>--%>
								<th width="7%" align="left"><s:property value="#orders.expressCompanyName" /></th>
								<th width="7%" align="left"><s:if test="#orders.netsiteName==null">
										<span style="color: red">待分配网点</span>
									</s:if> <s:elseif test="#orders.netsiteName!=null">
										<s:property value="#orders.netsiteName" />
									</s:elseif></th>
				<%-- 				<th width="3%" align="left">
									<s:if test="#orders.supportPrint==null">
										<span style="color: red"></span></s:if> 
									<s:elseif test="#orders.supportPrint==1">
										<span >是</span></s:elseif>
									<s:elseif test="#orders.supportPrint==0">
										<span >否</span></s:elseif>
								</th> --%>
								<th width="11%" align="left"><s:property value="#orders.fromProvinceName" /> <s:property value="#orders.fromCityName" /> <s:property value="#orders.fromDistrictName" /> <s:property value="#orders.fromAddress" /></th>
								<th width="5%" align="center"><s:date name='#orders.xdDate' format='yyyy-MM-dd HH:mm:ss' /></th>
								<%-- <th width="5%" align="left"><s:property value="#orders.content" /></th> --%>
								<th width="4%" align="left">
								<s:if test="#orders.dealStatus==null">
									<a id="<s:property value="#orders.id" />" href="javascript:void(0)" onclick="dealOrder(this)" style="color: Red">未处理</a></s:if> 
									<s:elseif test="#orders.dealStatus==1">
									<a id="<s:property value="#orders.id" />"   href="javascript:void(0)" onclick="dealOrder(this)" style="color: gray;">已处理</a></s:elseif>
									<s:elseif test="#orders.dealStatus==0">
									<a id="<s:property value="#orders.id" />"   href="javascript:void(0)" onclick="dealOrder(this)"  style="color: Red">未处理</a>
								  </s:elseif>
								</th>
								<th width="4%" align="left"><s:if test="#orders.basePaymentAmount==0.0">
										<span style="color: red">未支付</span>
									</s:if> <s:elseif test="#orders.basePaymentAmount!=null">
										<s:property value="#orders.basePaymentAmount" />
									</s:elseif></th>
								<th width="3%" align="left"><s:if test="#orders.giftMoney==null">
										<span style="color: #ccccc">未优惠</span>
									</s:if>	
									<s:elseif test="#orders.giftMoney ==0.0">
										<span style="color: #ccccc">未优惠</span>
									</s:elseif>
									 <s:elseif test="#orders.giftMoney !=0.0">
										<span style="color: red"><s:property value="#orders.giftMoney" /></span>
								</s:elseif></th>
							</tr>
						</s:iterator>
					</tbody>
				</table>
				<div class="panelBar">
					<div class="pages">
						<span>共${page.totalNum }条，共${page.totalPage }页</span>
					</div>
					<div class="pagination" targetType="navTab" totalCount="${page.totalNum }" numPerPage="${page.pageSize }" pageNumShown="10" currentPage="${page.currentPage }"></div>
				</div>
			</div>
		</form>


	</div>
	</body>
</c:if>
<c:if test="${code==0}">
${message}
</c:if>
</html>